package com.hub.videobrowsdownload

import android.content.Context
import android.graphics.Bitmap
import android.net.Uri
import android.util.Log
import android.webkit.ValueCallback
import android.webkit.WebChromeClient
import android.webkit.WebView
import com.security.brows.room.BrowsWebHistoryBean
import java.io.File
import java.io.FileOutputStream
import java.io.IOException

class BrowsMyWebChromeClient(val tabWebViewModel: BrowsTabWebViewModel): WebChromeClient(){
    override fun getDefaultVideoPoster(): Bitmap? {
        return Bitmap.createBitmap(10, 10, Bitmap.Config.ARGB_8888)
    }

    override fun onHideCustomView() {
        super.onHideCustomView()
    }

    override fun onProgressChanged(view: WebView?, newProgress: Int) {
        super.onProgressChanged(view, newProgress)
    }

    override fun onReceivedIcon(view: WebView?, icon: Bitmap?) {
        super.onReceivedIcon(view, icon)

        if (icon != null && view != null) {
            tabWebViewModel.webIcon = icon
            tabWebViewModel.saveHistory()
        }
    }


    override fun onReceivedTitle(view: WebView?, title: String?) {
        super.onReceivedTitle(view, title)
        if (title != null && view != null) {
            tabWebViewModel.webTitle.value = title
            tabWebViewModel.saveHistory()
        }
    }

    override fun onReceivedTouchIconUrl(view: WebView?, url: String?, precomposed: Boolean) {
        super.onReceivedTouchIconUrl(view, url, precomposed)
        if (!url.isNullOrEmpty()) {
            tabWebViewModel.webIconUrl = url
            tabWebViewModel.saveHistory()
        }

    }

    override fun onShowFileChooser(
        webView: WebView?,
        filePathCallback: ValueCallback<Array<Uri>>?,
        fileChooserParams: FileChooserParams?
    ): Boolean {
        return false
    }

}